<%--
  Created by IntelliJ IDEA.
  User: CR
  Date: 2019/10/30
  Time: 10:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>List Page</title>
<%--    <script src="https://code.jquery.com/jquery-1.12.4.min.js"--%>
<%--            integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="--%>
<%--            crossorigin="anonymous">--%>
<%--    </script>--%>
    <script src="scripts/jQuery-1.12.4.min.js"></script>
    <script>
        $(function () {
            $('.delete').click(function () {
                var href = $(this).attr('href');
                $('form').attr('action', href).submit();
                return false;
            });
        })
    </script>
</head>
<body>
    <form action="" method="POST">
        <input type="hidden" name="_method" value="DELETE">
    </form>

    <c:if test="${empty requestScope.employees}">
        没有任何员工信息
    </c:if>
    <c:if test="${!empty requestScope.employees}">
        <table border="1" cellpadding="10" cellspacing="0">
            <tr>
                <th>id</th>
                <th>lastName</th>
                <th>email</th>
                <th>gender</th>
                <th>department</th>
                <th>edit</th>
                <th>delete</th>
            </tr>
            <c:forEach items="${requestScope.employees}" var="emp">
                <tr>
                    <td>${emp.id}</td>
                    <td>${emp.lastName}</td>
                    <td>${emp.email}</td>
                    <td>${emp.gender == 0 ? 'female' : 'male'}</td>
                    <td>${emp.department.departmentName}</td>
                    <td><a class="edit" href="emp/${emp.id}">edit</a></td>
                    <td><a class="delete" href="emp/${emp.id}">delete</a></td>
                </tr>
            </c:forEach>
        </table>
    </c:if>
    <br />
    <a href="emp">Add New Employee</a>
</body>
</html>
